<?php
require('functions.php');
if(isset($_GET['conv'])){

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>A2P</title>
<link href="css/styles_menu.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
/* Terence Ordona, portal[AT]imaputz[DOT]com		 */
/* http://creativecommons.org/licenses/by-sa/2.0/	*/
/* begin some basic styling here					 */
body {
	background: #FFF;
	color: #000;
	font: normal normal 12px Verdana, Geneva, Arial, Helvetica, sans-serif;
	margin: 10px;
	padding: 0
}
table, td, a {
	color: #000;
	font: normal normal 12px Verdana, Geneva, Arial, Helvetica, sans-serif
}
h1 {
	font: normal normal 18px Verdana, Geneva, Arial, Helvetica, sans-serif;
	margin: 0 0 5px 0
}
h2 {
	font: normal normal 16px Verdana, Geneva, Arial, Helvetica, sans-serif;
	margin: 0 0 5px 0
}
h3 {
	font: normal normal 13px Verdana, Geneva, Arial, Helvetica, sans-serif;
	color: #008000;
	margin: 0 0 15px 0
}
/* end basic styling								 */
/* define height and width of scrollable area. Add 16px to width for scrollbar		 */
div.tableContainer {
	clear: both;
	border: 1px solid #963;
	height: 285px;
	overflow: auto;
	width: 756px
}
/* Reset overflow value to hidden for all non-IE browsers. */
html>body div.tableContainer {
	overflow: hidden;
	width: 756px
}
/* define width of table. IE browsers only				 */
div.tableContainer table {
	float: left;
	width: 740px
}
/* define width of table. Add 16px to width for scrollbar.		  */
/* All other non-IE browsers.										*/
html>body div.tableContainer table {
	width: 756px
}
/* set table header to a fixed position. WinIE 6.x only									  */
/* In WinIE 6.x, any element with a position property set to relative and is a child of	  */
/* an element that has an overflow property set, the relative value translates into fixed.	*/
/* Ex: parent element DIV with a class of tableContainer has an overflow property set to auto */
thead.fixedHeader tr {
	position: relative
}
/* set THEAD element to have block level attributes. All other non-IE browsers			*/
/* this enables overflow to work on TBODY element. All other non-IE, non-Mozilla browsers */
html>body thead.fixedHeader tr {
	display: block
}
/* make the TH elements pretty */
thead.fixedHeader th {
	background: #C96;
	border-left: 1px solid #EB8;
	border-right: 1px solid #B74;
	border-top: 1px solid #EB8;
	font-weight: normal;
	padding: 4px 3px;
	text-align: left
}
/* make the A elements pretty. makes for nice clickable headers				*/
thead.fixedHeader a, thead.fixedHeader a:link, thead.fixedHeader a:visited {
	color: #FFF;
	display: block;
	text-decoration: none;
	width: 100%
}
/* make the A elements pretty. makes for nice clickable headers				*/
/* WARNING: swapping the background on hover may cause problems in WinIE 6.x  */
thead.fixedHeader a:hover {
	color: #FFF;
	display: block;
	text-decoration: underline;
	width: 100%
}
/* define the table content to be scrollable											 */
/* set TBODY element to have block level attributes. All other non-IE browsers			*/
/* this enables overflow to work on TBODY element. All other non-IE, non-Mozilla browsers */
/* induced side effect is that child TDs no longer accept width: auto					 */
html>body tbody.scrollContent {
	display: block;
	height: 262px;
	overflow: auto;
	width: 100%
}
/* make TD elements pretty. Provide alternating classes for striping the table */
/* http://www.alistapart.com/articles/zebratables/							 */
tbody.scrollContent td, tbody.scrollContent tr.normalRow td {
	background: #FFF;
	border-bottom: none;
	border-left: none;
	border-right: 1px solid #CCC;
	border-top: 1px solid #DDD;
	padding: 2px 3px 3px 4px
}
tbody.scrollContent tr.alternateRow td {
	background: #EEE;
	border-bottom: none;
	border-left: none;
	border-right: 1px solid #CCC;
	border-top: 1px solid #DDD;
	padding: 2px 3px 3px 4px
}
/* define width of TH elements: 1st, 2nd, and 3rd respectively.		 */
/* Add 16px to last TH for scrollbar padding. All other non-IE browsers. */
/* http://www.w3.org/TR/REC-CSS2/selector.html#adjacent-selectors		*/
html>body thead.fixedHeader th {
	width: 200px
}
html>body thead.fixedHeader th + th {
	width: 240px
}
html>body thead.fixedHeader th + th + th {
	width: 316px
}
/* define width of TD elements: 1st, 2nd, and 3rd respectively.		 */
/* All other non-IE browsers.											*/
/* http://www.w3.org/TR/REC-CSS2/selector.html#adjacent-selectors		*/
html>body tbody.scrollContent td {
	width: 200px
}
html>body tbody.scrollContent td + td {
	width: 240px
}
html>body tbody.scrollContent td + td + td {
	width: 300px
}
-->
</style>
<script src="js/jquery-1.3.1.min.js" type="text/javascript"></script>
<script src="js/jquery.functions.js" type="text/javascript"></script>

<style type="text/css">
a{
	text-decoration:none;
}
img{
	border:none;
}
#contenedor{
	width:800px;
	margin:auto;
	margin-top:20px;
	border:2px solid #C0C0C0;
	background-color:#F2F2F2;
	padding-bottom:20px;
}
small{
	font-size:9px;
}

table{
	width:700px;
	margin:auto;
}
td{
	border-bottom:0px solid #D3D3D3;
	padding:5px 0px 5px;
	text-align: left;
}

th{
	background-color:#CDCDCD;
	padding:5px 0px 5px;
}

form{
	border:2px solid #C0C0C0;
	width:500px;
	margin:auto;
	margin-bottom:20px;
}

form p{
	margin:auto;
	width:450px;
	margin-top:5px;
	margin-bottom:3px;
}
form input{
	border:1px solid #CCCCCC;
	padding:3px;
}

form .text{
	width:400px;
}

#resultado{	
	border:none;
}

.textos {
	text-align: left;
}
.textos label {
	text-align: left;
}

iframe{
		
}

.frame{
	visibility:hidden;
	display:none;	
}

	.progress-bar {
     border: 1px solid #56577A; 
     width: 200px; 
     margin: 5px; 
     padding: 1px; 
     background: #fff;
	 float: left;
	 text-align:center;
   }

   .bar {
     height: 15px;
	 font-size: 11px;
	 text-indent:-9000px;
	 text-align:center;
   }
   
   #percentage{
    float: left;
	margin-left: 10px;
	margin-top:4px;
   }
</style>
<script src="progressbar.js" type="text/javascript"></script>
<script type="text/javascript">
var prefijos = new Array();

<?php 
$conexion = mysql_connect("localhost", "admin", "Xurpas123");
mysql_select_db("smsnic", $conexion);
$result1= mysql_query("SELECT prefijos FROM movistar", $conexion) or die(mysql_error());
if (mysql_num_rows($result1)){ 
$i=0;
while ($row1 = @mysql_fetch_array($result1)){
echo "prefijos[".$i."] = ".$row1['prefijos'].";";
$i=$i+1;
}

}

mysql_close($conexion);
?>

function validarfh(){
var hora = document.getElementById('hora');
var minutos = document.getElementById('min');

if(hora.value=='' || minutos.value=='')
{
	alert('Estimado usuario ingrese la hora exacta del envio');
	hora.focus();
	return false;
}
else
{	
	if ((/^[0-9]+$/.test(hora.value) == false) || (/^[0-9]+$/.test(minutos.value) == false))
	{
		alert('Estimado usuario el campo de la hora no puede contener carateres.');
		hora.focus();
		return false;
	}

	else
	{
		if((parseInt(hora.value) > 23) || (parseInt(hora.value) < 0))
		{
			alert('Estimado usuario el campo de la hora no es valido (0-23).');
			hora.focus();
			return false;
		}
		else
		{
			if((parseInt(minutos.value) > 59) || (parseInt(minutos.value) < 0))
			{
				alert('Estimado usuario el campo de los minutos no es valido (0-59).');
				minutos.focus();
				return false;
			}
			else
			{	
			
				
				return true;
		
			}
		}
	}
}
}



function enviar(){

	var telefonos = jQuery.trim($('#msisdn').val());
	var elem = telefonos.split('\n');
	var mensaje = jQuery.trim($('#sms').val());
	var x = 0;
	var audi = new Array();
	var frame ="";
	var fecha= document.getElementById('fecha_nacimiento').value;
	var hora= document.getElementById('hora').value+":"+document.getElementById('min').value;
	
	var seleccionado = document.getElementById('seleccionado').value;
	var edad = 0;
	var edad2 = 0;
	
	if(seleccionado==1)
	{
			edad =  document.getElementById('edad').value;
		}
		else if (seleccionado == 2)
		{
			edad =  document.getElementById('edad2').value;
			}
		else if (seleccionado == 3)
		{
			edad =  document.getElementById('edad3').value;
			edad2 =  document.getElementById('edad4').value;
			}
	
	if(mensaje=="")
	{
		alert("No ha ingresado el mensaje que se enviara...");
	}
	else
	{
		for(var i=0; i< elem.length; i++) 
		{		
		x=0;	
			for(var j=0; j < prefijos.length; j++)
				{
			
					if(elem[i].substring(0,4)==prefijos[j])
						{
							x=1;
							
							audi[i] = document.createElement("IFRAME");
							audi[i].id = "audi"+i;
							frame="audi"+i;
							audi[i].src = "conversaciones.php?telefono=505"+elem[i]+"&operadora=1&mensaje="+mensaje.value+"&estado=3&fecha="+fecha+"&hora="+hora+"&seleccionado="+seleccionado+"&edad="+edad+"&edad2="+edad2;	
							document.body.appendChild(audi[i]);
							//document.getElementById(frame).className='frame';	
							
						}
				
				}
				if(x==0){
							if(elem[i]!=""){					
							audi[i] = document.createElement("IFRAME");
							audi[i].id = "audi"+i;
							frame="audi"+i;
							audi[i].src = "conversaciones.php?telefono=505"+elem[i]+"&operadora=2&mensaje="+mensaje.value+"&estado=3&fecha="+fecha+"&hora="+hora+"&seleccionado="+seleccionado+"&edad="+edad+"&edad2="+edad2;	
							document.body.appendChild(audi[i]);
							//document.getElementById(frame).className='frame';	
							}
							
				}
	
		}

		initialize();
		
	}	
}
	


function cargar(){
	var grupo = document.getElementById('grupo');
	location.href="prgsms.php?grupo="+grupo.value;
}
function agregar(x){
	//
	var variable = document.getElementById('var'+x);
	var msg = document.getElementById('sms');
	msg.value=msg.value+variable.name
	
	
}

//variable del sistema
function agregarVS(x){

	var msg = document.getElementById('sms');
	msg.value=msg.value+x;
	
	
}

function cambiar(){

id=document.getElementById("condicion").value;

	if(id=="0")
	{
	
	div = document.getElementById('Dcondicion');				
				div.style.display='none';
				
	
		div3 = document.getElementById('Dcondicion3');
		div3.style.display = 'none';
		
		div2 = document.getElementById('Dcondicion2');
		div2.style.display = 'none';
	}
	else if (id=="1")
	{
				
		div = document.getElementById('Dcondicion');
		document.getElementById('seleccionado').value= document.getElementById('condicion').value;

		div.style.display = '';
		
		div3 = document.getElementById('Dcondicion3');
		div3.style.display = 'none';
		
		div2 = document.getElementById('Dcondicion2');
		div2.style.display = 'none';
		}
		else if (id=="2")
	{
				
		div = document.getElementById('Dcondicion2');
		document.getElementById('seleccionado').value= document.getElementById('condicion').value;

		div.style.display = '';
		
		div3 = document.getElementById('Dcondicion3');
		div3.style.display = 'none';
		
		div1 = document.getElementById('Dcondicion');
		div1.style.display = 'none';
		}
		else if (id=="3")
	{
				
		div = document.getElementById('Dcondicion3');
		document.getElementById('seleccionado').value= document.getElementById('condicion').value;

		div.style.display = '';
		
		div2 = document.getElementById('Dcondicion2');
		div2.style.display = 'none';
		
		div1 = document.getElementById('Dcondicion');
		div1.style.display = 'none';
		
		}
	
	
}

	function mostrarDIV()
	{
		div = document.getElementById('Dcondicion');
		document.getElementById("rp").value=id;
		div.style.display = "";
		}
		
		function ocultarDIV() {

				div = document.getElementById('Dcondicion');
				
				div.style.display='none';

		}
		

function deshab() {
  frm = document.forms['form'];
  for(i=0; ele=frm.elements[i]; i++)
    ele.disabled=true;
	
	frm2 = document.forms['form2'];
  for(i=0; ele2=frm2.elements[i]; i++)
    ele2.disabled=true;
}

function hab() {
  frm = document.forms['form'];
  for(i=0; ele=frm.elements[i]; i++)
    ele.disabled=false;
	
	frm2 = document.forms['form2'];
  for(i=0; ele2=frm2.elements[i]; i++)
    ele2.disabled=false;
}
		
</script>
<script type="text/javascript">
$(document).ready(function(){
	// mostrar formulario de actualizar datos
	$("table tr .modi a").click(function(){
		$('#tabla').hide();
		$("#formulario").show();
		$.ajax({
			url: this.href,
			type: "GET",
			success: function(datos){
				$("#formulario").html(datos);
			}
		});
		return false;
	});
	
});

</script>


<style type="text/css" title="currentStyle">
			@import "tabla/demo_page.css";
			@import "tabla/demo_table.css";
		.derecha {
	text-align: right;
	vertical-align: middle;
}
</style>
		<script type="text/javascript" language="javascript" src="tabla/jquery.js"></script>
		<script type="text/javascript" language="javascript" src="tabla/jquery.dataTables.js"></script>
		<script type="text/javascript" charset="utf-8">
			$(document).ready(function() {
				$('#example').dataTable();
			} );
		</script>
</head> 

<body bgcolor="#FFFFFF" id="send_sms"> 
<iframe id="mov" height="1px" style="visibility:hidden">
</iframe>



<table id="detalle">
<tr>
<td>
<div style="width:100%;">
			
			<div id="demo">
<table>
<tr>
<td height="16">
<a href="envios_conversacion.php?conv=<?php echo $_GET['conv']; ?>" ><img src="img/add.png" alt="Agregar dato" />Agregar Mensaje</a>
</td>
<td class="derecha" height="16">
<a href="index_conversacion.php" >Regresar<img src="img/close.png" alt="Agregar dato" /></a>
</td>
</tr>
</table>
<br/><br/>
	<table id="example" class="display">
    <thead>
   		<tr>
        	<th width="110px" class="center">Fecha</th>           
    		<th class="center" width="70px">Hora</th> 
            <th class="center">Motivo</th>    		
            <th class="center" width="200px">Mensaje</th>
            <th class="center">T&eacute;lefonos</th>
            <th class="center">Editar</th>
            <th class="center">Eliminar</th>
           
        </tr>
        </thead>
        <tbody>
<?php
$link = mysql_connect("localhost", "admin", "Xurpas123");
mysql_select_db("smsnic",$link);

$result1= mysql_query("select fecha, hora, mensaje, GROUP_CONCAT(telefono SEPARATOR', ') as telefono, id, reg, asunto
from
(SELECT CONCAT( users.nombre, ' ', users.apellido ) AS usuario, fecha, hora, pais, operadora.nombre, telefono, mensaje, estado.descripcion, `mensajes`.id, reg, `prgconv`.`nombre` as asunto
FROM envios, telefonos, mensajes, operadora, users, estado, prgconv
WHERE telefonos.id = envios.id_telefono
AND mensajes.id = envios.id_mensaje
AND telefonos.operadora_id = operadora.id
AND envios.id_user = users.id
AND estado.id=envios.estado
AND prgconv.id=envios.reg
AND envios.id_conv=".$_GET['conv'].") as temp
group by fecha, hora, mensaje, reg, asunto", $link) or die(mysql_error());

if(mysql_num_rows($result1)) {
	while( $cliente = @mysql_fetch_array($result1) ){
	?>
	
		  <tr class="gradeB">
	         <td class="center"><?php echo $cliente['fecha'] ?></td>
              
			  <td class="center"><?php echo $cliente['hora'] ?></td>
              <td><?php echo $cliente['asunto'] ?></td>
              <td><?php echo $cliente['mensaje'] ?></td>
              <td class="center"><?php echo $cliente['telefono'] ?></td>
              <td class="center"><span class="modi"><a href="envios_conversacion.php?conv=<?php echo $_GET['conv']; ?>&msg=<?php echo $cliente['id']; ?>&fecha=<?php echo $cliente['fecha']; ?>&hora=<?php echo $cliente['hora']; ?>&prg=<?php echo $cliente['reg']; ?>" ><img src="img/database_edit.png" title="Editar" alt="Editar" /></a></span></td>
			  <td class="center"><span class="dele"><a href="conversaciones4.php?&conv=<?php echo $_GET['conv']; ?>&fecha1=<?php echo $cliente['fecha']; ?>&hora1=<?php echo $cliente['hora']; ?>&prg=<?php echo $cliente['reg']; ?>&msg=<?php echo $cliente['id']; ?>"><img src="img/delete.png" title="Eliminar" alt="Eliminar" /></a></span></td>

		  </tr>
	<?php
	}
}
?>
</tbody>
<tfoot>

   		<tr>
   			<th class="center">Fecha</th>
            <th class="center">Hora</th>    		
            <th class="center">Motivo</th>    		
            <th class="center">Mensaje</th>
            <th class="center">T&eacute;lefonos</th>            
            <th class="center">Editar</th>
            <th class="center">Eliminar</th>
             
        </tr>

</tfoot>
</table>   
</div>
</div>
</td>
</tr>
</table>

<script>
function desplegar(){
	var tabla=document.getElementById('formulario');
		var detalle=document.getElementById('detalle');
		
		tabla.style.display='';
		detalle.style.display='none';
	
}
function ocultar(){
	var tabla=document.getElementById('formulario');
		var detalle=document.getElementById('detalle');
		
		tabla.style.display='none';
		detalle.style.display='';
	
}
</script>

</body>

</html>
<?php
}
?>